from matplotlib import pyplot as plt
import matplotlib.patches as mpatches

import numpy as np

# Affichage de la table
def AfficheTable(P,cible,poids):
    n = len(poids)
    mat = 0.5*np.ones((n+1,cible+1))
    for i in range(n+1):
        for s in range(cible+1):
            if (i,s) in P:
                mat[i][s] = P[(i,s)]

    plt.close('all')
    fig, ax = plt.subplots()
    ax.imshow(mat, cmap='RdYlGn')

    ax.set_xticks(np.arange(-0.5, cible+1, 1), minor=True)
    ax.set_yticks(np.arange(-0.5, n+1, 1), minor=True)
    ax.grid(which='minor', color='black', linewidth=0.5)

    patch_vrai = mpatches.Patch(color='green', label='Vrai')
    patch_faux = mpatches.Patch(color='red', label='Faux')
    patch_nc = mpatches.Patch(color='khaki', label='Non calculé')
    ax.legend(handles=[patch_vrai, patch_faux, patch_nc],
               loc='upper right',
               fontsize=8,           # Taille du texte
               handlelength=1,       # Largeur des carrés
               handleheight=1,       # Hauteur des carrés
               borderpad=0.3,        # Marge intérieure
               labelspacing=0.3)     # Espacement entre les lignes

    plt.xlabel('Somme cible s')
    plt.ylabel('Nombre d\'éléments i')
    plt.title('Table de programmation dynamique')

    plt.show()


poids = [10,10,10,1,5,10]





